package com.cardvalue.sys.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cardvalue.sys.R;
import com.cardvalue.sys.entity.MoreListDto;

import java.util.ArrayList;
import java.util.List;

/**
 * 更多页面的adapter
 * Created by cardvalue on 2016/4/1.
 */
public class MoreRecylerAdapter extends RecyclerView.Adapter{
    private List<MoreListDto> mMoreListDto= new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;
    public MoreRecylerAdapter(Context context, List<MoreListDto> mMoreListDto){//Context context,
       this.context=context;
        this.mMoreListDto=mMoreListDto;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context,R.layout.list_more,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
     if(holder instanceof ViewHolder){
         ViewHolder viewHolder=(ViewHolder)holder;
         MoreListDto moreListDto  =mMoreListDto.get(position) ;
         if(moreListDto!=null){
             if(moreListDto.isShow()){
                 viewHolder.asd.setVisibility(View.VISIBLE);
             }else{
                 viewHolder.asd.setVisibility(View.GONE);
             }

             if(moreListDto.getTitle().equals("融资攻略")||moreListDto.getTitle().equals("在线客服")){
                 viewHolder.bottom.setVisibility(View.VISIBLE);
             }
             viewHolder.image1.setImageResource(moreListDto.getIconIndex());
             viewHolder.text1.setText(moreListDto.getTitle());
         }
     }
    }



    @Override
    public int getItemCount() {
        return mMoreListDto!=null?mMoreListDto.size():0;
    }



    class ViewHolder extends RecyclerView.ViewHolder{
        ImageView image1;
        TextView text1;
        RelativeLayout root;
        View asd;
        View bottom;

        public ViewHolder(View itemView) {
            super(itemView);
            init(itemView);
            //给列表item点击点击事件
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(itemClickListener!=null){
                        itemClickListener.onItemClick(v,getLayoutPosition());
                    }
                }
            });

        }

        private void init(View view){
            image1 = (ImageView) view.findViewById(R.id.image1);
            text1 = (TextView) view.findViewById(R.id.text1);
            root = (RelativeLayout) view.findViewById(R.id.root);
            asd= view.findViewById(R.id.and);
            bottom= view.findViewById(R.id.bottom);
        }
    }


    //对外部暴漏点击事件接口
    public interface OnItemClickListener{
        void onItemClick(View v,int position);
    }

    public OnItemClickListener itemClickListener;

    public void setItemClickListener(OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

}
